$(function() {
	$('#vue_vm_list div').hide();
});

var userVipCard = {
	vipTransactId: '',
	vipCardId: '',
	name: '',
	sex: '',
	cardId: '',
	liveAddress: '',
	phoneNumber: '',
	email: '',
	status: '',
	surplusMonths: '',
	buckleNumber: '',
	useStatus: '',
	payCostStatus: '',
	createTime: '',
	updateTime: '',
	createId: getLoginedUser()? getLoginedUser().staffId: '',
	createName: getLoginedUser()? getLoginedUser().staffName: '',
	updateId: getLoginedUser()? getLoginedUser().staffId: '',
	updateName: getLoginedUser()? getLoginedUser().staffName: '',
	remark: '',
	vipCardName: '',
};

var view = {
	data: userVipCard
};

var vue_vm = new Vue({
	el: '#vue_vm',
	data: view
});

function save() {
	view.data.sex = (view.data.sex==''? 0: parseInt(view.data.sex));
	view.data.status = (view.data.status==''? 0: parseInt(view.data.status));
	view.data.surplusMonths = (view.data.surplusMonths==''? 0: parseInt(view.data.surplusMonths));
	view.data.buckleNumber = (view.data.buckleNumber==''? 0: parseInt(view.data.buckleNumber));
	view.data.useStatus = (view.data.useStatus==''? 0: parseInt(view.data.useStatus));
	
	if(view.data.vipCardId=='') {
		alert('请选择VIP卡');
		return;
	}
	if(view.data.payCostStatus=='') {
		alert('请选择状态');
		return;
	}

	save_basic(path+'/userVipCard/save', {userVipCard:view.data}, function() {
		alert('VIP卡办理成功');
		window.open('3-1-2vipbookprint.html?pageParam='+encodeURIComponent(JSON.stringify(view.data)));
	});
}

function deleteBatch() {
	deleteBatch_basic(path+'/userVipCard/deleteBatch');
}

vipCardFind = function(vipCardId) {
	if($('#vue_vm_list').length==0) {return;}
	$('#vue_vm_list div').hide();
	if(!vipCardId || vipCardId=='') {return;}
	
	var vue_vm_list = null;
	find_basic_by_json(path+'/vipCard/findOne', {id: vipCardId}, function(response) {
		$('#vue_vm_list').html(gl_vue_vm_list_html);
		
		vue_vm_list = new Vue({
			el: '#vue_vm_list',
			data: {
				todos: response.data
			},
			methods: {
				getSubsidizationValue:function(subsidization, subsidizationValue) {
					return subsidization=='无补助'? '': subsidizationValue;
				},
				getSubsidizationUnit:function(subsidization) {
					return subsidization=='饭卡补助'? '元': (subsidization=='包餐补助'?'天':'');
				},
				getSubsidizationText:function(subsidization, subsidizationValue) {
					return subsidization + this.getSubsidizationValue(subsidization, subsidizationValue) + this.getSubsidizationUnit(subsidization);
				},
			}
		});
		
		view.data.vipCardId = vipCardId;
		view.data.surplusMonths = response.data[0].useMonths;
		view.data.buckleNumber = response.data[0].buckleNumber;
		view.data.houseTypeId = response.data[0].houseTypeId;
		view.data.houseTypeName = response.data[0].houseTypeName;
		view.data.price = response.data[0].price;
		view.data.useMonths = response.data[0].useMonths;
		view.data.consumptionType = response.data[0].consumptionType;
		view.data.discount = response.data[0].discount;
		view.data.pricePerDay = response.data[0].pricePerDay;
		view.data.subsidizationType = response.data[0].subsidizationType;
		view.data.subsidization = response.data[0].subsidization;
		view.data.subsidizationValue = response.data[0].subsidizationValue;
		view.data.consumptionWay = response.data[0].consumptionWay;
		if(vue_vm_list) {
			view.data.subsidizationText = vue_vm_list.getSubsidizationText(view.data.subsidization, view.data.subsidizationValue);
		}
		
		$('#vue_vm_list div').show();
	});
}
